﻿/*
数字分组 
Time Limit:1000MS  Memory Limit:32768K


Description:
将1,2...9共9个数分成三组,分别组成三个三位数,且使这三个三位数构成1:2:3的比例,
试求出所有满足条件的三个三位数. 例如:三个三位数192,384,576满足以上条件 

Input:
无 
Output:
按从小到大的顺序，输出满足条件的数，每行三个，数之间有一个空格。 192 384 576 
*/
#include <iostream>
#include <cstring>
using std::cout;
using std::endl;

#define MAX_ELEMS 10
#define MAX_CHARS 4

class GroupThree
{
public:
	inline static void group();
protected:
	inline static bool setFlag(char* num);
private:
	static char num[MAX_CHARS+1];
	static unsigned digits[MAX_ELEMS];
};
char GroupThree::num[]={0};
unsigned GroupThree::digits[]={0};

bool GroupThree::setFlag(char* num)
{
	unsigned i=0u;

	if (digits[0])
		return false;
	for (; i<MAX_CHARS-1; ++i)
		if(digits[num[i]-'0'])return false;
		else
		   digits[num[i]-'0']++;
	return true;
}
void GroupThree::group()
{
	unsigned i;

	for (i=123u; i<=345u; i++)
	{
		bool flag=false;
		memset(digits, 0, sizeof(int)*MAX_ELEMS);

		itoa(i, num, 10);
		flag=setFlag(num);
		
		itoa(i<<1, num, 10);
		flag=setFlag(num);
		if (!flag)continue;
		
		itoa(i+(i<<1), num, 10);
		flag=setFlag(num);
		if (flag)
		{
			cout<<i<<" "<<(i+i)<<" "<<(i+i+i)<<endl;
		}
	}
}

int main(int argc, char* argv[])
{
	GroupThree::group();
	return 0;
}